package com.zhu.tool_test.map;

import java.awt.geom.Arc2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
/**
 * @program: tool_test
 * @description: 地图工具类
 * http://jszx-jxpt.cuit.edu.cn/javaapi/java/awt/geom/class-use/point2d.html
 * @author: ggBall
 * @create: 2021-01-13 14:27
 **/

public class MapTools {

    public static List genPointList() {
        List list = new ArrayList();
        Point2D.Double p1 = new Point2D.Double(113.943811,22.534549);
        Point2D.Double p2 = new Point2D.Double(113.940649,22.532229);
        Point2D.Double p3 = new Point2D.Double(113.948518,22.532847);
//        Point2D.Double p4 = new Point2D.Double(1.0,0.5);
////        Point2D.Double p5 = new Point2D.Double(1.0,1.0);
////        Point2D.Double p6 = new Point2D.Double(1.0,0.5);
////        Point2D.Double p7 = new Point2D.Double(1.0,0.0);
////        Point2D.Double p8 = new Point2D.Double(0.5,0.0);

        //Point2D.Double[] points = {p1,p2,p3,p4,p5,p6,p7,p8};
        Point2D.Double[] points = {p1,p2,p3};
        for (int i = 0; i < points.length; i++) {
            list.add(points[i]);
        }

        return list;
    }

    /**
    * @Description 检查 点位是否在在区域内
    * @Author  ggBall
    * @Date   2021/1/13 14:33
    * @Param
     * @param point
     * @param polygon
    * @Return      boolean
    * @Exception
    *
    */
    public static boolean checkWithPath(Point2D.Double point, List<Point2D.Double> polygon) {
        GeneralPath p = new GeneralPath();
        Point2D.Double first = polygon.get(0);
        p.moveTo(first.x,first.y);
        for(Point2D.Double d: polygon) {
            p.lineTo(d.x,d.y);
        }
        p.lineTo(first.x,first.y);
        p.closePath();
        return p.contains(point);
    }

    public static void main(String[] args) {
//        List list = genPointList();
//        Point2D.Double p1 = new Point2D.Double(113.945068,22.533565);
////        Point2D.Double p2 = new Point2D.Double(0.2,0.3);
////        Point2D.Double p3 = new Point2D.Double(1.5,0.1);
////        Point2D.Double p4 = new Point2D.Double(0.8,0.0);
//        //Point2D.Double p5 = new Point2D.Double(0.08,0.01);
//        Point2D.Double p6 = new Point2D.Double(113.947296,22.532396);
//        List<Point2D.Double> testList = new ArrayList();
//        testList.add(p1);
////        testList.add(p2);
////        testList.add(p3);
////        testList.add(p4);
////        testList.add(p5);
//        testList.add(p6);
//        for(Point2D.Double each:testList) {
//            boolean flag = checkWithPath(each,list);
//            System.out.println(each.toString() + " is in polygon: " + flag);
//        }
        MapTools mapTools = new MapTools();
        mapTools.polarPoints();

    }

    public void drawPie() {
        Arc2D.Double arc = new Arc2D.Double(Arc2D.PIE);

    }

    public void polarPoints(){
        Double x = 1.23D;
        Double y = 3.45D;
        Double ang = -30D;
        Double dist = 30D;
        Point2D.Double tagrt = new Point2D.Double(x + dist * Math.cos(ang), y + dist * Math.sin(ang));
        System.out.println("tagrt = " + tagrt.toString());
    }
}

